//-
//- Copyright (c) Microsoft. All rights reserved.
//- Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-

extends ../layout

block js_doc_ready
  | if (typeof initializeManageFilter == 'function') { initializeManageFilter(); }
  | if (typeof initializeMembershipFilter == 'function') { initializeMembershipFilter(); }

block content
  div.container

    h1
      span.capitalize= organization.name + ' '
      small Organization

    div.container
      div.row(style='margin-top:16px')
        div.col-md-3.col-lg-3
          div.metro-box.ms-dark-blue
            a(href=organization.baseUrl + 'new-repo')
              h3 Create a repo
              p NEW REPO
        div.col-md-3.col-lg-3
          div.metro-box.ms-blue
            a(href=organization.baseUrl + 'teams?set=available')
              h3 Join a team
              p VIEW TEAMS
        div.col-md-3.col-lg-3
          div.metro-box.ms-purple
            a(href='https://github.com/orgs/' + organization.name + '/new-team', target='_new')
              h3 Add a team
              p NEW TEAM
        div.col-md-3.col-lg-3
          div.metro-box(class=accountInfo.isMembershipPublic === true ? 'ms-green' : 'ms-yellow')
            a(href=organization.baseUrl + 'membership')
              if accountInfo.isMembershipPublic === true
                h3 Public member
              else
                h3 Concealed
              p= 'PUBLIC MEMBERSHIP'

      if accountInfo.isSudoer
        h2 SUDO
        p Your account has sudoer rights for this organization. You have additional capabilities enabled to help ensure the health of the organization, its teams and repos. Please use care.

      if accountInfo.organizationOverview.teams.maintainer && accountInfo.organizationOverview.teams.maintainer.length
        if accountInfo.pendingApprovals && accountInfo.pendingApprovals.length && accountInfo.pendingApprovals.length > 0
          h2 Pending Approvals
          p
            a.btn.btn-default(href='./approvals/') See all pending #{organization.name} approvals (#{accountInfo.pendingApprovals.length})
        if accountInfo.organizationOverview.teams.maintainer
          h2.capitalize #{organization.name} Teams You Maintain
          div.container
            table.table#manage-table
              thead
                tr
                  th GitHub Name
                  // th Organization
                  th.thirtypercent Manage
              tbody
                each team in accountInfo.organizationOverview.teams.maintainer
                  tr
                    td
                      a.btn.btn-sm.btn-muted(href=organization.baseUrl + 'teams/' + team.slug + '/')= team.name
                    // td= team.organization.name
                    td.thirtypercent
                      p
                        a.btn.btn-sm.btn-default(href=organization.baseUrl + 'teams/' + team.slug + '/') Manage Team

      if accountInfo && accountInfo.membershipStatus === 'active' && accountInfo.isMembershipPublic !== true
        h1 Go public with your support of the #{organization.name} organization
        p Your profile on GitHub currently does not list your participation in the #{organization.name} organization. By making your association public, others in the community will see you listed on the page for #{organization.name} and your personal GitHub profile page will show the logo, too.
        p
          a.btn.btn-default.btn-sm(href=organization.baseUrl + 'membership') Learn more

      h2 Team Memberships

      if accountInfo.teamsMaintainedHash
        p Here are teams that you are a member of but do not maintain.

      if accountInfo.organizationOverview.teams.member && accountInfo.organizationOverview.teams.member.length
        table.table#membership-table
          thead
            tr
              th Team
              th.thirtypercent View
          tbody
            - var everyoneTeamId = organization.invitationTeam ? organization.invitationTeam.id : -1
            each team in accountInfo.organizationOverview.teams.member
              if team.id && accountInfo.teamsMaintainedHash && accountInfo.teamsMaintainedHash[team.id] !== undefined
                // Skipping this team since they are already maintaining it
              else
                tr
                  td
                    a.capitalize.btn.btn-sm.btn-muted(href='/' + team.organization.login + '/teams/' + team.slug, target='_new')= team.name
                  td.thirtypercent
                    p
                      a.btn.btn-default.btn-sm(href='/' + team.organization.login + '/teams/' + team.slug, target='_new')
                        | Open on GitHub
      else
        //-p You are not currently a member of any GitHub teams that grant you permission to specific repositories. You may be pre-approved to join teams.
        p You are not currently a member of any GitHub teams for #{organization.name}. <em>This view is cached.</em>
      p
        a.btn.btn-default(href=organization.baseUrl + 'teams')= (accountInfo.organizationOverview.teams.member && accountInfo.organizationOverview.teams.member.length) ? 'Join another team' : 'Join a team'

      if accountInfo.orgUser
        hr
        - var orgAccount = accountInfo.orgUser
        - var orgUser = accountInfo.orgUser.organizationProfile
        h1(style='margin:36px 0') About the #{organization.name} Organization
        div.row
          div.col-md-3.col-lg-3
            p
              img.img-thumbnail.img-responsive(src=orgAccount.avatar(400), alt=(orgUser.name || orgUser.login))
            h3= orgUser.name
            h4= orgUser.login
            p(style='margin-top:18px')
              a.btn.btn-sm.btn-muted(href='https://github.com/' + organization.name, target='_new')
                | Open on GitHub
          div.col-md-8.col-lg-8.col-md-offset-1.col-lg-offset-1
            div.row
              div.col-md-6.col-lg-6
                if orgUser.company
                  h6 Company
                  p= orgUser.company
                if orgUser.location
                  h6 Location
                  p= orgUser.location
                if orgUser.email
                  h6 E-mail
                  p= orgUser.email
                if orgUser.blog
                  h6 On the Web
                  p
                    a(href=orgUser.blog, target='_new')= orgUser.blog
                if orgAccount.getProfileCreatedDate && orgAccount.getProfileCreatedDate()
                  h6 Created
                  p
                    time(datetime=orgAccount.getProfileCreatedDate().toISOString())= orgAccount.getProfileCreatedDate().toDateString()
                if orgAccount.getProfileUpdatedDate && orgAccount.getProfileUpdatedDate()
                  h6 Updated
                  p
                    time(datetime=orgUser.getProfileUpdatedDate().toISOString())= orgUser.getProfileUpdatedDate().toDateString()
                hr
                if organization.configuredOrganizationRepositoryTypes
                  h6 Supported Repository Types
                  ul.list-unstyled
                    li Public
                    if organization.configuredOrganizationRepositoryTypes == 'publicprivate' || organization.configuredOrganizationRepositoryTypes == 'private'
                      li Private

              div.col-md-6.col-lg-h6
                h6 Repositories
                if orgUser.public_repos
                  h2
                    = orgUser.public_repos + ' '
                    small Public
                if orgUser.total_private_repos
                  h2
                    = orgUser.total_private_repos + ' '
                    small Private

                hr
                h6 Remaining Repositories
                if orgUser.plan && orgUser.plan.private_repos
                  h2.capitalize
                    = orgUser.plan.name + ' '
                    small Plan
                  h2
                    = (orgUser.plan.private_repos - orgUser.total_private_repos) + ' '
                    small Private
                h2
                  | &infin;&nbsp;
                  small Public

      if organization.legacyTrainingResourcesLink
        - var tr = organization.legacyTrainingResourcesLink
        if tr.organization && tr.organization.length && tr.organization.length > 0
          hr
          h3 Organization Resource#{tr.organization.length > 1 ? 's' : ''}
          ul.list-unstyled
            each resource in tr.organization
              li
                p
                  a(href=resource.link, target='_new')
                    = resource.title + ' '
                    i.glyphicon.glyphicon-share-alt
                  if resource.text
                    br
                    small= resource.text

      hr
      p
        a.btn.btn-default(href=organization.baseUrl + 'leave') Leave #{organization.name}